/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2014年12月29日         luwei
 */

package com.coocaa.launcher.sidebar.left.item.qrcode;

import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;

import com.coocaa.launcher.SettingActivity;
import com.coocaa.launcher.framework.sidebar.item.Item;
import com.coocaa.launcher.framework.sidebar.item.ItemView;
import com.coocaa.x.service.XServiceManager;

public class QrCode extends Item {
    private ImageView mExtraView = null;

    public QrCode(Context context) {
        super(context);
    }

    @Override
    public void onItemFocusChange(View v, boolean focus) {
        // if (focus)
        // {
        // if (mExtraView == null)
        // {
        // initExtraView();
        // }
        // mExtraViewListener.addExtraView(mItemView.getX() + mItemView.getWidth(), mItemView.getY()
        // + mItemView.getHeight(), mExtraView);
        // }else {
        // mExtraViewListener.removeExtraVeiw(mExtraView);
        // }
        super.onItemFocusChange(v, focus);
    }

    //
    // private void initExtraView()
    // {
    // mExtraView = new ImageView(mContext);
    // SkinManager.getInstance().setBackgroundResource(mExtraView, R.drawable.mobile_qr_code);
    // }

    @Override
    public boolean onItemKeyEvent(View v, int keycode, KeyEvent keyEvent) {
        return false;

    }

    @Override
    public void onItemClick(View v) {
        try {
            boolean ret = XServiceManager.getLiteCCConnectorService().starQRCode();
            if (!ret) {
                Intent intent = new Intent(mContext, SettingActivity.class);
                intent.putExtra("type", mType.toString());
                mContext.startActivity(intent);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        super.onItemClick(v);
    }

    @Override
    public ItemView createItemView() {
        if (mItemView == null) {
            mItemView = new QrCodeItem(mContext);
        }
        return mItemView;
    }

}
